package com.shiguiwu.springmybatis.spring.aop.proxyfactory;

import com.shiguiwu.springmybatis.spring.aop.principle.FunsService;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;

import java.lang.reflect.Method;

/**
 * @description: ProxyFactory 简化aop开发
 * @author: stone
 * @date: Created by 2021/12/26 14:00
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.aop.proxyfactory
 */
public class ProxyFactoryTests {

    public static void main(String[] args) {
        ProxyFactory proxyFactory = new ProxyFactory();

        //添加目标对象
        proxyFactory.setTarget(new FunsService());

        //添加增强
        proxyFactory.addAdvice(new MethodBeforeAdvice() {
            @Override
            public void before(Method method, Object[] objects, Object o) throws Throwable {
                System.out.println("我在你方法之前执行");
            }
        });

        Object proxy = proxyFactory.getProxy();

        FunsService funsService = (FunsService) proxy;

        funsService.cashOut("shiguiwu", 120);

    }
}
